#!/usr/bin/python3
from typing import List
from types import SimpleNamespace
import requests

import dto


def GetTaijiHq(name: str, date: str, num: int) -> List[dto.SharesDto]:
    """"""
    payload = {'name': name, 'date': date, 'num': num}
    try:
        r = requests.get('https://www.taiji666.top/taiyi/hq/get-symbol-n', params=payload, verify=False)
        if r.status_code != 200:
            print("status_code:", r.status_code, ",msg:", r.text)
            return None
        rsp = r.json(object_hook=lambda obj: SimpleNamespace(**obj))
        print("rsp.code:", rsp.code)
        if rsp.code != 200:
            """"""
            print("code:", rsp.code, ",Msg:", rsp.msg)
            return None
        req: List[dto.SharesDto] = []
        for d in rsp.data:
            """"""
            o = dto.SharesDto()
            o.date = d.trade_date
            o.open = d.open
            o.close = d.close
            o.preClose = d.pre_close
            o.high = d.high
            o.low = d.low
            o.volume = d.vol
            o.amount = d.amount
            o.pctChg = d.pct_chg
            o.change = d.change
            req.append(o)
        """"""
        return req
    except Exception as ex:
        print("ex:", ex)
        return None

